package com.ddyx.service.impl;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;

import com.ddyx.entity.EventDealslog;
import com.ddyx.entity.EventLog;
import com.ddyx.entity.EventStorelog;
import com.ddyx.mapper.DealDetailsMapper;
import com.ddyx.mapper.TimeLineMapper;
import com.ddyx.service.ITimeLineService;

@Service
public class TimeLineServiceImpl implements ITimeLineService {

	@Resource
	TimeLineMapper timeLineMapper;
	@Resource
	DealDetailsMapper dealDetailsMapper;
	
	@Override
	public List<Map<String, Object>> selectTimeLine(int page, int size, String contactId) {
		List<Map<String, Object>> list = new ArrayList<>();
		int start = (page-1)*size;
		List<EventLog> eventLogList = timeLineMapper.getEventLog(start, size, contactId);
		if(eventLogList!=null) {
			for(EventLog eventLog : eventLogList) {
				Map<String, Object> map = new HashMap<>();
				map.put("event", eventLog);
				if("1".equals(eventLog.getEventType())) {
					EventStorelog store = timeLineMapper.getEventStoreLog(eventLog.getEventId());
					map.put("store", store);
				}
				if("2".equals(eventLog.getEventType())) {
					EventDealslog deals = timeLineMapper.getEventDealsLog(eventLog.getEventId());
					deals.setDetails(timeLineMapper.getDetailsByBillNo(deals.getBillNo()));
					map.put("deals", deals);
				}
				list.add(map);
			}
		}
		return list;
	}

	@Override
	public int eventLogCount(int page, int size, String contactId) {
		int start = (page-1)*size;
		return timeLineMapper.eventLogCount(start, size, contactId);
	}

}
